/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package broad.dao;


import broad.bean.Log;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;

/**
 *
 * @author Rafael
 */
public class DAOLog extends DAOGenerics <Log, Integer> {

    @Override
    public Log buscar(Integer obj) {
        SessionFactory sf = new AnnotationConfiguration().configure().buildSessionFactory();
        Session s = sf.openSession();

        try {
            return buscar(obj, s);

        } finally {
            s.close();
        }
    }

    @Override
    public Log buscar(Integer obj, Session s) {
        String sql = "from Log where idLog = :id";

        Query qr = s.createQuery(sql);
        qr.setParameter("id", obj);

        return (Log) qr.uniqueResult();
    }

    @Override
    public List<Log> buscarTodos() {
        SessionFactory sf = new AnnotationConfiguration().configure().buildSessionFactory();
        Session s = sf.openSession();

        try {
            return buscarTodos(s);

        } finally {
            s.close();
        }
    }

    @Override
    public List<Log> buscarTodos(Session s) {
        String sql = "from Log";

        Query qr = s.createQuery(sql);

        return (List<Log>) qr.list();
    }

}
